package com.pai4j.ugc.controller;

import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.domain.vo.response.moment.MomentVO;
import com.pai4j.ugc.service.moment.MomentKeywordSearchService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ugc-service/moment/search")
public class MomentSearchController {

    @Resource
    private MomentKeywordSearchService momentKeywordSearchService;

    @GetMapping("/keyword")
    public PAIResponseBean<PAIPageResponseBeanUtil<List<MomentVO>>> searchByKeyword(@RequestParam String keyword,
                                                                                    @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                                                                    @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return PAIResponseBeanUtil.success(momentKeywordSearchService.searchByKeyword(keyword, pageNo, pageSize));
    }

    @PostMapping("/keywords")
    public PAIResponseBean<PAIPageResponseBeanUtil<List<MomentVO>>> searchByKeywords(@RequestBody List<String> keywords,
                                                                                     @RequestParam(required = false, defaultValue = "time_desc") String sort,
                                                                                     @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                                                                     @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return PAIResponseBeanUtil.success(momentKeywordSearchService.searchByKeywords(keywords, sort, pageNo, pageSize));
    }
    @PostMapping("/keywords/advanced")
    public PAIResponseBean<PAIPageResponseBeanUtil<List<MomentVO>>> searchByKeywordsAdvanced(@RequestBody List<String> keywords,
                                                                                             @RequestParam(required = false, defaultValue = "AND") String mode,
                                                                                             @RequestParam(required = false, defaultValue = "time_desc") String sort,
                                                                                             @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                                                                             @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return PAIResponseBeanUtil.success(momentKeywordSearchService.searchByKeywordsWithMode(keywords, mode, sort, pageNo, pageSize));
    }

}

